package com.snail.snailvr.views;

import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.snail.snailvr.R;
import com.snail.snailvr.utils.JsonUrl;
import com.snail.snailvr.utils.Util;
import com.umeng.analytics.MobclickAgent;

import butterknife.Bind;
import butterknife.OnClick;

public class AboutActivity extends BaseToolbarActivity {

    public static Intent getIntent(Context context){
        Intent intent = new Intent(context, AboutActivity.class);
        return intent;
    }

    @Bind(R.id.first_virtual)
    TextView first_virtual;

    @Bind(R.id.version)
    TextView version;

    @Bind(R.id.use_terms)
    TextView use_terms;

    @Override
    protected void handleIntent() {}

    @Override
    protected void initView() {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setupToolbar(toolbar, getResources().getString(R.string.about_us), -1);

        // 下划线
        first_virtual.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        first_virtual.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = WebViewActivity.getIntent(AboutActivity.this, JsonUrl.VR_OFFICIAL_URL);
                startActivity(intent);
            }
        });

        version.setText(String.format(getString(R.string.version_name), Util.getVersionName(this)));

        use_terms.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_about;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }
    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }
    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }
    @Override
    protected boolean onToolbarMenuItemClick(MenuItem item) {
        return false;
    }

    @OnClick(R.id.use_terms)
    public void useTerms(){
        String language = Util.getCurrentLanguage();

        if ("zh_CN".equals(language)){
            Intent intent = WebViewActivity.getIntent(this, JsonUrl.USE_TERMS_CHINESE_URL);
            startActivity(intent);
        }
        else if ("zh_TW".equals(language)){
            Intent intent = WebViewActivity.getIntent(this, JsonUrl.USE_TERMS_FAN_URL);
            startActivity(intent);
        }
        else if ("en_US".equals(language)){
            Intent intent = WebViewActivity.getIntent(this, JsonUrl.USE_TERMS_ENGLISH_URL);
            startActivity(intent);
        }
    }
}
